﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class UserArticle : YuanlinUserControl,
        IReplyConverter<CompanyNewsReply, GetOperation>
    {
        protected Repeater list;
        private CompanyNews companyNews;

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            requestBinders.Add(RequestHelper.BuildGetCompanyNewsRequest(this));
        }

        private void BindData()
        {
            EntityList companyNewss = new EntityList()  ;

            if (companyNews != null)
            {
                companyNews.Views.Value++;
                BusinessManager.UpdateCompanyNews(companyNews);

                companyNewss.Add(companyNews);
            }

            list.DataSource = companyNewss;
            list.DataBind();

        }

        #region IReplyConverter<CompanyNewsReply,GetOperation> Members

        public void ConvertReply(CompanyNewsReply reply, GetOperation operation)
        {
            if (reply != null)
            {
                companyNews = reply.Entity as CompanyNews;

                if (!IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
